export function isFunction (func: any) {
  return (typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]')
}

export function snapToGrid (grid: any, pendingX: any, pendingY: any, scale = 1) {
  const x = Math.round((pendingX / scale) / grid[0]) * grid[0]
  const y = Math.round((pendingY / scale) / grid[1]) * grid[1]

  return [x, y]
}

export function getSize (el: any) {
  const rect = el.getBoundingClientRect()

  return [
    parseInt(rect.width),
    parseInt(rect.height)
  ]
}

export function computeWidth (parentWidth: any, left: any, right: any) {
  return parentWidth - left - right
}

export function computeHeight (parentHeight: any, top: any, bottom: any) {
  return parentHeight - top - bottom
}

export function restrictToBounds (value: any, min: any, max: any) {
  if (min !== null && value < min) {
    return min
  }

  if (max !== null && max < value) {
    return max
  }

  return value
}
